<template>
  <div
    class="dCard"
    :style="{
      backgroundColor: isCheck ? '#409eff' : '#a6a9ad',
    }"
  >
    <i class="iconfont icon-a-shebei5"></i>
    <div class="dName">{{ dName }}</div>
    <div class="status" v-if="use != null">
      {{ deviceStatus ? "运行中" : "停止" }}
    </div>
  </div>
</template>

<script>
export default {
  props: {
    //设备名称
    dName: {
      type: String,
      default: "A1",
    },
    //是否选中
    isCheck: {
      type: Boolean,
      default: false,
    },
    //设备状态
    status: {
      type: Object,
      default: () => {
        return {};
      },
    },
    use: {
      type: Number,
      default: null,
    },
  },
  data() {
    return {
      deviceStatus: false,
    };
  },
  watch: {
    status: {
      handler() {
        if (!this.status.hasOwnProperty("plcSignals")) return false;
        let item = this.status.plcSignals.find((item) => item.addr == this.use);
        this.deviceStatus = !item ? false : item.message == -1 ? false : true;
      },
      deep: true,
      immediate: true,
    },
  },
  computed: {},
  created() {},
  mounted() {},
  methods: {},
};
</script>

<style scoped lang="scss">
.dCard {
  position: relative;
  width: 100%;
  height: 100px;
  background-color: #409eff;
  display: flex;
  margin-bottom: 10px;
  .iconfont {
    width: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 2.4rem;
  }
  .dName {
    flex: 1;
    height: 100%;
    display: flex;
    align-items: center;
    font-size: 1.8rem;
    font-weight: bold;
    color: #fff;
    letter-spacing: 5px;
  }
  .status {
    position: absolute;
    right: 5px;
    top: 3px;
    min-width: 70px;
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 1.2rem;
    font-weight: bold;
    color: #fff;
  }
}
.dCard:hover {
  transform: translateY(-1px);
  box-shadow: 3px 3px 3px rgba(0, 0, 0, 10%);
  cursor: pointer;
}
</style>
